@include('backstage/public/_header')
    <style>
        .add_tab td span #thume {
            line-height: 100px;
            color: #d94040;
            font-size: 14px;
            text-align: center;
        }
        .textarea-lg{float: left;display: inline-block;line-height:100px;margin:16px 10px;}
        .add_tab tr td{ padding:5px; border-right:1px solid #e1e1e1; border-bottom:1px solid #ddd; }
    </style>
    <div class="result_wrap">
        <!--快捷導航 開始-->
        <div class="result_content">
            <div class="short_wrap">
                <a href="add"><i class="fa fa-plus"></i>添加新慘數</a>
                <!-- <a href="javascript:void(0);" onclick="del();" ><i class="fa fa-recycle"></i>批量刪除</a> -->
                <a href="javascript:void(0);" onclick="window.location.reload();"><i class="fa fa-refresh"></i>更新排序</a>
            </div>
        </div>
        <!--快捷導航 結束-->
    </div>
    <!--面包屑導航 結束-->
    <div class="result_wrap">
        <form id="form_data">
            {{csrf_field()}}
            <table class="add_tab">
                <tbody>
                @foreach ($data as $vb)
                    <tr id="list_{{$vb->id}}">
                        <td class="tc">
                            <input type="text" onkeyup="value=value.replace(/[^\d{1,}\-\d{1,}|\d{1,}]/g,'')" onblur="sort('sort',{{$vb->id}})" sort="{{$vb->sort_order}}" maxlength="3" value="{{$vb->sort_order}}" id="sort_{{$vb->id}}" style="width: 30px;">
                        </td>
                        <td width="170" style="text-align: right;">{{$vb->name}}：</td>
                        <td>
                            {!! $vb->_html !!}
                            {{--<input type="text" class="lg" name="{{$vb->code}}"  value="{{$vb->text}}">--}}
                            {{-- <span style="color: darkred;"><i class="fa fa-exclamation-circle yellow"></i>{{$vb->tip}}</span> --}}
                        </td>
                        <td><a href="javascript:void(0);" onclick="del({{$vb->id}});">刪除</a></td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            <div class="btn_group">
                <input type="button" value="修改" id="btnSub" onclick="onSubmit();">
                <!-- <input type="button" class="back" onclick="history.go(-1)" value="返回"> -->
            </div>
        </form>
        <div class="tips">
            <h3>添加新慘數說明</h3>
            <p>1、系統創建慘數不允許被刪除</p>
            <!-- <p>2、頂級分類無父分類</p> -->
            <p>2、分類唯壹標誌為分類鏈接的網址標識，排序：數字越大越靠前</p>
            <p>3、點擊修改 -&gt; 修改慘數，添加新慘數-&gt; 進入編輯慘數詳細表單</p>
        </div>
    </div>
    <script type="text/javascript">
        function sort(name,id){
            var olddata = $('#'+name+'_'+id).attr('sort');
            var getdata = $('#'+name+'_'+id).val();
            if(olddata != getdata ){
                $.post("{{$update_sort}}", { 'id': id,'sort': $('#'+name+'_'+id).val(),"_token":"{{ csrf_token() }}"},
                function (data){
                    // console.log(data);
                    if(data.status==1){
                        $('#'+name+'_'+id).attr('sort',getdata);
                    }
                    if(data.status==-1){
                        layer.alert(data.message, {icon: 2,anim:6});
                    }
                    if(data.status==0){
                        layer.msg(data.message, {icon: 2});
                        // window.location.reload(); 
                        $('#'+name+'_'+id).val(olddata);
                    }
                }, "json");
            }
        }
        
        function onSubmit(){
            var vfTime = 2;
            var timer=null;
            if (vfTime!=0 && timer!=null){
                layer.msg('操作過於頻繁', {icon: 7,anim: 6});
                // setTimeout(function(){$("#chiContent").focus();}, 1500);
                return false;
            }
            var form = new FormData(document.getElementById("form_data"));
//             var req = new XMLHttpRequest();
//             req.open("post", "${pageContext.request.contextPath}/public/testupload", false);
//             req.send(form);
            // console.log(form);
            $.ajax({
                url:"{{$doedit}}",
                type:"post",
                data:form,
                processData:false,
                contentType:false,
                dataType : "json",
                success:function(data){
                    // console.log(data);
                    if(data.status==1){
                        layer.msg(data.message, {icon: 6});
                        setTimeout(function(){
                            parent.main.location.reload();
                        },2000);
                    }else if(data.status==0){
                        layer.msg(data.message, {icon: 5});
                    }else if(data.status==-1){
                        layer.alert(data.message, {icon: 2,anim:6});
                    }else{
                        layer.msg(data.message, {icon: 7});
                        setTimeout(function(){
                            parent.main.location.reload();
                        },2000);
                    }
                    clearInterval(timer);
                    timer = setInterval(setTime, 1000, "1");
                    
                },
                error:function(e){
                    layer.msg(e, {icon: 5,anim: 6});
                    clearInterval(timer);
                    timer = setInterval(setTime, 1000, "1");
                }
            });
            function setTime(){
                vfTime --;
                if(vfTime==0){
                    clearInterval(timer);
                }
            }     
            // get();//此處為上傳文件的進度條
        }
        //刪除
        function del(aid){
            aid = aid ? aid : getChecked();
            // console.log(aid);
            //詢問框
            layer.confirm('刪除後不可恢復，確定要刪除嗎？', {
              btn: ['確定','取消'] //按鈕
            }, function(){
                aid = aid.toString();
                // console.log(aid);
                if(aid == '') return layer.msg('未選中任何數據', {icon: 2,anim: 6});
                // layer.msg('正在刪除...', {icon: 16,shade: 0.01});
                $.post("{{$dodel}}", { 'idstr':aid,"_token":"{{ csrf_token() }}"},
                function (data){
                    if(data.status==1){
                        layer.msg('正在刪除...', {icon: 16,shade: 0.01});
                        setTimeout(function(){
                            aid = aid.split(',');
                            $.each(aid, function(i,n){
                                $('#list_'+n).remove();
                            });
                            layer.msg(data.message, {icon: 1});
                        },2000);
                    }else if(data.status==0){
                        layer.msg(data.message, {icon: 2});
                    }else if(data.status==-1){
                        layer.alert(data.message, {icon: 2,anim:6});
                    }else if(data.status==2){
                        layer.msg(data.message, {icon: 7});
                    }else{
                        layer.msg('未知原因，刪除失敗', {icon: 2});
                    }
                }, "json");
            }, function(){
              // layer.msg('未做任何操作', {
              //   time: 20000, //20s後自動關閉
              //   btn: ['明白了', '知道了']
                // layer.msg('未做任何操作', {icon: 2});
            });
            
        }
    </script>
@include('backstage/public/_footer')